<template>
	<view>
		<home :cur="PageCur" v-if="PageCur=='home'" :key="commponent1Key"></home>
		<people v-if="PageCur=='people'" :key="commponent2Key"></people>
		<work v-if="PageCur=='work'" :key="commponent2Key"></work>
		<worklist v-if="PageCur=='worklist'" :key="commponent2Key"></worklist>
		<clockin v-if="PageCur=='clockin'" :key="commponent2Key"></clockin>
		<attendance v-if="PageCur=='attendance'" :key="commponent2Key"></attendance>
		<view class="cu-bar tabbar bg-white shadow foot">
			<view v-for="(item,index) in tabBarList" :key="index" :class="PageCur==item.pagePath?'action text-green':'action text-gray'" @click="NavChange" :data-cur="item.pagePath">
				<view :class='item.iconPath'></view>{{item.text}}
			</view>
		</view>
	</view>
</template>

<script>
	// #ifdef APP-PLUS
	import {
		queryBatteryOptimizeStatus,
		requestIgnoreBatteryOptimization,
		startForegroundService,
		stopForegroundService
	} from "@/uni_modules/hr-keep-alive";
	// #endif
	export default {
		props:{
			cur:String,
		},
		watch: {
			cur: {
				immediate: true,
				handler:function(val,oldVal){
					console.log('cur',val,oldVal)
				    this.initTabBar()
				},
			},
		},
		data() {
			return {
				PageCur: 'home',
				commponent1Key: 0,
				commponent2Key: 0,
				title: 'Hello',
				isIgnoreBatteryOptimization: false,
				tabBarList:[],
			}
		},
		onLoad:function(){
			// 每隔2秒更新当前时间
			    this.timer = setInterval(() => {
			      // this.$router.go(0)
			    }, 10000);
				console.log("aaaaaaaaaaa===")
			// #ifdef APP-PLUS
			// startForegroundService();
			queryBatteryOptimizeStatus(3434344).then(res => {
				if (!res) {
					requestIgnoreBatteryOptimization().then(result => {
						this.isIgnoreBatteryOptimization = result;
					})
				} else {
					this.isIgnoreBatteryOptimization = true;
				}
			})
			// #endif
			this.PageCur='home'
			++this.commponent1Key
			++this.commponent2Key
		},
		methods: {
			NavChange: function(e) {
				this.PageCur = e.currentTarget.dataset.cur
			},
			initTabBar() {
				let that = this;
				that.$http.get("/oa/oaSysTabBar/list",{params:{pageNo: 1, pageSize:10,column:'sort',order:'asc',status:'Y'}}).then(res=>{
				  if(res.data.success){
					  for(let annItem of res.data.result.records){
					  	that.tabBarList.push(annItem)							
					  }
				  }else{
					that.$tip.toast(res.data.message);
				  }
				});
			}
		}
	}
</script>

<style>

</style>
